@(log: uk.bl.monitrix.model.CrawlLog)

@import tags.{heritrixStatus, navbar, embedParam}

@main("Monitrix - URLs") {
  @navbar("/urls")
}{
  <h2>Total URLs: @log.countEntries</h2>
  <h3>Revisited: @log.countRevisits</h3>
  
  <table class="table monitrix-hostinfo">
    <tr>
      <td class="monitrix-hostinfo-label">Compressability</td>
      <td style="width:90%">
        <div class="not-loaded">
          <div class="monitrix-barchart-container">
            <div class="monitrix-barchart-y-label-container">
              <span class="monitrix-barchart-y-label">Number of URLs</span>
            </div>
            <div class="monitrix-barchart-container-right">
              <div class="monitrix-barchart-chart-area" id="compressability-histogram"></div>
              <div class="monitrix-barchart-x-label">Compressability - (compressed length / uncompressed length)</div>
            </div>
          </div>
          
          <div class="load-button">
            <span class="btn" onclick="loadHistogram();">Generate Histogram</span>
          </div>
        </div>
      </td>
    </tr>
  </table>
  
  <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/morris.css")">
  <script src="@routes.Assets.at("javascripts/raphael-min.js")" type="text/javascript"></script>
  <script src="@routes.Assets.at("javascripts/morris.min.js")" type="text/javascript"></script>  
  <script src="@routes.Assets.at("javascripts/querystring.js")" type="text/javascript"></script>   
  <script>
    var lastHoveredCompressability;
    
    function loadHistogram() {
        $('.load-button').remove();
        $('.not-loaded').addClass('loading');
        
        $.getJSON('/api/urls/compressability', function(data) {
          $('.not-loaded').removeClass('not-loaded').removeClass('loading');
          Morris.Bar({
            element: 'compressability-histogram',
			data: data,
            xkey: 'x',
            ykeys: ['y'],
            labels: [ '# of Hosts' ],
            hideHover: 'false',
            barColors: [ '#850303' ],
            hoverCallback: function(index, options) {
              var row = options.data[index];
              lastHoveredCompressability = row.x;
              
              var embeddable = (QueryString.get('embeddable') != undefined) ? "&embeddable=true" : "";
              var targetLink = '/search?type=compressability&min=' + lastHoveredCompressability +
            		  '&max=' + (lastHoveredCompressability + 0.04) + embeddable;
              
              var html = 
            	    '<div class="morris-hover-row-label"><a href="' + targetLink + '">Compressed/Uncompressed ' + row.x + '</a></div>' + 
            	    '<div class="morris-hover-point" style="color: #850303">' +
                      row.y + ' URLs' +
                    '</div>';
              return html;
            }
          });        
        });
    }
  </script>
}